<include file="Public/head"/>
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css"/>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type="text/css">
    .agent {
        margin: 12px 0
    }

    .agent_1, .agent_2 {
        display: block;
        margin-top: 10px;
        width: 100%;
        height: 25px;
    }

    .agent_2 {
        margin-left: 0px;
        clear: both;
    }

    .agent_input {
        border: 1px solid #d7d7d7;
        float: left;
        height: 24px;
        line-height: 24px;
        margin: 0 10px 10px 0;
        text-align: center;
        width: 150px;
    }

    #status,#level,#is_expert,
    #is_recommend_expert {
        -moz-appearance: none;
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/sanjiao.jpg") no-repeat scroll 130px 5px;
        border: 1px solid #d7d7d7;
        color: #666;
        float: left;
        font-family: "微软雅黑";
        height: 26px;
        line-height: 26px;
        margin: 0 10px 0px 0;
        text-align: left;
        width: 154px;
    }

    .xiaci1 {
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/zhong_pic.jpg") no-repeat scroll 130px 4px;
        border: 1px solid #d7d7d7;
        float: left;
        height: 24px;
        line-height: 24px;
        margin-right: 10px;
        padding-left: 10px;
        text-align: left;
        width: 140px;
    }

    .table thead tr > td, .table tbody tr > td {
        text-align: center;
        vertical-align: middle;
    }

    .tanShang .daiJingW {
        padding: 20px 0 0 50px;
    }

    .tanShang .daiJingW .tipmsg {
        font-size:14px;
    }
</style>
</head>
<include file="Public/common_header"/>
<div class="mian">
    <include file="Public/sidebar" menu="zhgl.grzh"/>
    <div class="mianR">
        <h3 class="cha">个人用户管理</h3>
        <div class='yuSuo clearfix'>
            <form id="searchFrom">
                <div class="agent_1">
                    <input type="text" name="uid" placeholder="请输入个人ID" class="agent_input"/>
                    <input type="text" name="user_name" placeholder="请输入昵称" class="agent_input"/>
                    <input type="text" name="real_name" placeholder="请输入姓名" class="agent_input"/>
                    <input type="text" name="phone" placeholder="请输入电话" class="agent_input"/>
                    <select name="level" id="level">
                        <option value="0">请选择等级</option>
                        <option value="1">注册</option>
                        <option value="2">银牌</option>
                        <option value="3">金牌</option>
                        <option value="4">白金</option>
                        <option value="5">钻石</option>
                    </select>
                    <select name="is_expert" id="is_expert">
                        <option value="0">请选择是否牛人</option>
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                </div>
                <div class="agent_2">
                    <select name="is_recommend_expert" id="is_recommend_expert">
                        <option value="0">请选择是否推荐牛人</option>
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                    <select name="status" id="status">
                        <option value="0">请选择状态</option>
                        <option value="1">启用</option>
                        <option value="2">禁用</option>
                    </select>
                    <input type="text" name="start_time" placeholder="开始时间" value="" class="xiaci1 xin-text"
                           id="start_time" readonly>
                    <input type="text" name="end_time" placeholder="结束时间" value="" class="xiaci1 xin-text" id="end_time"
                           readonly/>
                    <input class="suoSou" type="button" name="clcw_search" value="筛选">
                    <input class="suoSou" type="button" name="agent_all" value="全部"
                           onclick="window.location.href='/ClcwUser/index'">
                </div>
            </form>
        </div>
        <div class="yuList">
            <div class="listBox" id="listBox"></div>
        </div>
    </div>
    <!--账户设置弹出窗口-->
    <div class="tanShang set_user_status" style="display:none">
        <h3>账户设置</h3>
        <ul class="daiJingW">
            <li class="clearfix tipmsg"></li>
            <li class="clearfix">
                <input type="hidden" name="user_id" id="user_id">
                <input type="hidden" name="user_status" id="user_status">
                <input type="button" value="确定" class="queding" id="qd_set_user_status"/>
                <input type="button" value="取消" class="quxiao"/>
            </li>
        </ul>
    </div>
    <!--取消牛人弹出窗口-->
    <div class="tanShang cancel_user_expert" style="display:none">
        <h3>取消牛人</h3>
        <ul class="daiJingW">
            <li class="clearfix tipmsg"></li>
            <li class="clearfix">
                <input type="hidden" name="expert_id" id="expert_id">
                <input type="button" value="确定" class="queding" id="qd_cancel_user_expert"/>
                <input type="button" value="取消" class="quxiao"/>
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</div>
<script type="text/javascript">
    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null)
            return unescape(r[2]);
        return null; //返回参数值
    }
    get_list();
    function get_list() {
        var url = mkUrl();
        var p = getUrlParam('p');
        if (p != null) {
            var purl = "?p=" + p;
        } else {
            var purl = "?p=1";
        }
        $.get("/ClcwUser/clcwUserList" + purl, url, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    $("input[name='clcw_search']").click(function () {
        get_list();
    });
    function get_page(p) {
        var url = mkUrl();
        $.get("/ClcwUser/clcwUserList/" + encodeURI("p/" + p), url, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    function mkUrl() {
        var url = "";
        var uid = $("input[name='uid']").val();
        var user_name = $("input[name='user_name']").val();
        var real_name = $("input[name='real_name']").val();
        var phone = $("input[name='phone']").val();
        var level = $("#level").val();
        var is_expert = $("#is_expert").val();
        var is_recommend_expert = $("#is_recommend_expert").val();
        var status = $("#status").val();
        var start_time = $("input[name='start_time']").val();
        var end_time = $("input[name='end_time']").val();

        if (uid) {
            url += '&uid=' + uid;
        }
        if (user_name) {
            url += '&user_name=' + user_name;
        }
        if (real_name) {
            url += '&real_name=' + real_name;
        }
        if (phone) {
            url += '&phone=' + phone;
        }
        if (level) {
            url += '&level=' + level;
        }
        if (is_expert) {
            url += '&is_expert=' + is_expert;
        }
        if (is_recommend_expert) {
            url += '&is_recommend_expert=' + is_recommend_expert;
        }
        if (status) {
            url += '&status=' + status;
        }
        if (start_time) {
            url += '&start_time=' + start_time;
        }
        if (end_time) {
            url += '&end_time=' + end_time;
        }
        return url;
    }

    function set_user_status(nick_name, user_id, user_status) {
        var status_name = '';
        if (user_status == 2) {
            status_name = '禁用';
        } else {
            status_name = '普通';
        }
        var str = '确定将用户<b style="color:red"> ' + nick_name + ' </b>设置为 <b style="color:red">' + status_name + '</b> 状态吗？';
        $('.tipmsg').html(str);
        $('#user_id').val(user_id);
        $('#user_status').val(user_status);
        $('.set_user_status').show();
    }

    $('#qd_set_user_status').click(function () {
        var uid = $('#user_id').val();
        var user_status = $('#user_status').val();
        var post_data = {
            'user_id': uid,
            'user_status': user_status
        }
        $(".yunBei").css("display", "block").unbind('click')
        $(".loading").fadeIn();
        $.post('/ClcwUser/setUserStatus', post_data, function (data) {
            if (data.code == 200) {
                $('.set_user_status').hide();
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                $(".loading").fadeOut();
                shibai_alert(data.msg);
            }
        }, 'JSON');
    });

    $("#start_time").ymdateplugin({
//        showTimePanel: true,
//        changeMonth: true,
//        changeYear: true
    });
    $("#end_time").ymdateplugin({
//        showTimePanel: true,
//        changeMonth: true,
//        changeYear: true
    });

    function cancel_user_expert(user_id) {
        var str = '取消后将不可恢复，确定取消该用户为牛人吗？';
        $('.tipmsg').html(str);
        $('#expert_id').val(user_id);
        $('.cancel_user_expert').show();
    }

    $('#qd_cancel_user_expert').click(function () {
        var uid = $('#expert_id').val();
        var post_data = {
            'user_id': uid
        }
        $(".yunBei").css("display", "block").unbind('click')
        $(".loading").fadeIn();
        $.post('/ClcwUser/cancelUserExpert', post_data, function (data) {
            if (data.code == 200) {
                $('.cancel_user_expert').hide();
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                $(".loading").fadeOut();
                shibai_alert(data.msg);
            }
        }, 'JSON');
    });

    function set_user_top(user_id, is_top) {
        var post_data = {
            'user_id': user_id,
            'is_top': is_top
        }
        $(".yunBei").css("display", "block").unbind('click')
        $(".loading").fadeIn();
        $.post('/ClcwUser/setUserTop', post_data, function (data) {
            if (data.code == 200) {
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                $(".loading").fadeOut();
                shibai_alert(data.msg);
            }
        }, 'JSON');
    }
</script>
<include file="Public/foot"/>
